package 作业监听;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * create at 2018/10/17
 * author: suveng
 * email: suveng@163.com
 **/
public class CronTrigerE  {
    public static void main(String[] args) throws SchedulerException {
        //1. 创建job
        JobDetail job= JobBuilder.newJob(HelloJob.class).build();

        TriggerKey triggerKey=new TriggerKey("test","suveng");

        //2.创建trigger
        CronTrigger cronTrigger= TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
//       3.创建触发器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        ListenerManager listenerManager = scheduler.getListenerManager();
        listenerManager.addJobListener(new MyJobListener());

//        开启触发器
        scheduler.start();
//        添加定时任务
        scheduler.scheduleJob(job,cronTrigger);
    }
}
